package model.vo

class R<T> {
    var code = 0
    var msg: String? = null
    var data: T? = null
        private set

    constructor() {}
    constructor(code: Int, msg: String?) {
        this.code = code
        this.msg = msg
    }

    constructor(code: Int, msg: String?, data: T) {
        this.code = code
        this.msg = msg
        this.data = data
    }

    fun setData(data: T) {
        this.data = data
    }

    companion object {
        fun <T> succeed(): R<T> {
            return R(200, "成功")
        }

        fun <T> succeed(msg: String?): R<T> {
            return R(200, msg)
        }

        fun <T> succeed(data: T): R<T> {
            return R(200, "成功", data)
        }

        fun <T> succeed(msg: String?, data: T): R<T> {
            return R(200, msg, data)
        }

        fun <T> failed(): R<T> {
            return R(500, "失败")
        }

        fun <T> failed(data: T): R<T> {
            return R(500, "失败", data)
        }

        fun <T> failed(msg: String?, data: T): R<T> {
            return R(500, msg, data)
        }

        fun <T> failed(msg: String?): R<T> {
            return R(500, msg)
        }

        fun <T> failed(code: Int, msg: String?): R<T> {
            return R(code, msg)
        }

        fun <T> failed(code: Int, msg: String?, data: T): R<T> {
            return R(code, msg, data)
        }
    }
}